/*
  Copyright � 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  ThanhNam ERP Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using VINETLIFE.DO;
/// <summary>
/// Summary description for cmsLocationDAL
/// </summary>
namespace VINETLIFE.DAL 
{
    
    public class cmsLocationDAL  : BaseDAL
    {
    	#region Private Variables
			
		#endregion
		
		#region Public Constructors
				public cmsLocationDAL()
				{
					//
					// TODO: Add constructor logic here
					//
					
				}
		#endregion       

	
		
		#region Public Methods
        public int Insert(cmsLocationDO objcmsLocationDO)
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "spcmsLocation_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@LocationCode", SqlDbType.NVarChar);
Sqlparam.Value = objcmsLocationDO.LocationCode;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Location", SqlDbType.NVarChar);
Sqlparam.Value = objcmsLocationDO.Location;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Description", SqlDbType.NVarChar);
Sqlparam.Value = objcmsLocationDO.Description;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@CreatedDate", SqlDbType.DateTime);
Sqlparam.Value = objcmsLocationDO.CreatedDate;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@CreatedById", SqlDbType.Int);
Sqlparam.Value = objcmsLocationDO.CreatedById;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@LastSaveDate", SqlDbType.DateTime);
Sqlparam.Value = objcmsLocationDO.LastSaveDate;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@LastModifiedId", SqlDbType.Int);
Sqlparam.Value = objcmsLocationDO.LastModifiedId;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@ParentId", SqlDbType.Int);
Sqlparam.Value = objcmsLocationDO.ParentId;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@OrderId", SqlDbType.Int);
Sqlparam.Value = objcmsLocationDO.OrderId;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
Sqlparam.Direction = ParameterDirection.ReturnValue;
Sqlcomm.Parameters.Add(Sqlparam);

           
            int result =base.ExecuteNoneQuery(Sqlcomm);
            
            if(!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
				result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(cmsLocationDO objcmsLocationDO)
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "spcmsLocation_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@LocationId", SqlDbType.Int);
Sqlparam.Value = objcmsLocationDO.LocationId;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@LocationCode", SqlDbType.NVarChar);
Sqlparam.Value = objcmsLocationDO.LocationCode;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Location", SqlDbType.NVarChar);
Sqlparam.Value = objcmsLocationDO.Location;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Description", SqlDbType.NVarChar);
Sqlparam.Value = objcmsLocationDO.Description;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@CreatedDate", SqlDbType.DateTime);
Sqlparam.Value = objcmsLocationDO.CreatedDate;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@CreatedById", SqlDbType.Int);
Sqlparam.Value = objcmsLocationDO.CreatedById;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@LastSaveDate", SqlDbType.DateTime);
Sqlparam.Value = objcmsLocationDO.LastSaveDate;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@LastModifiedId", SqlDbType.Int);
Sqlparam.Value = objcmsLocationDO.LastModifiedId;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@ParentId", SqlDbType.Int);
Sqlparam.Value = objcmsLocationDO.ParentId;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@OrderId", SqlDbType.Int);
Sqlparam.Value = objcmsLocationDO.OrderId;
Sqlcomm.Parameters.Add(Sqlparam);


            
            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);
            
            int result=base.ExecuteNoneQuery(Sqlcomm);
            
             if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);
                
            return result;

           
        }

        public int Delete(cmsLocationDO objcmsLocationDO)
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "spcmsLocation_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@LocationId", SqlDbType.Int);
Sqlparam.Value = objcmsLocationDO.LocationId;
Sqlcomm.Parameters.Add(Sqlparam);


            
            int result=base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

         public int DeleteAll()
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "spcmsLocation_DeleteAll";

            int result=base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public cmsLocationDO Select(cmsLocationDO objcmsLocationDO)
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "spcmsLocation_GetByPK";
            SqlParameter Sqlparam;
  

            Sqlparam = new SqlParameter("@LocationId", SqlDbType.Int);
Sqlparam.Value = objcmsLocationDO.LocationId;
Sqlcomm.Parameters.Add(Sqlparam);


            
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if(!Convert.IsDBNull(dr["LocationId"]))
objcmsLocationDO.LocationId=Convert.ToInt32(dr["LocationId"]);
if(!Convert.IsDBNull(dr["LocationCode"]))
objcmsLocationDO.LocationCode=Convert.ToString(dr["LocationCode"]);
if(!Convert.IsDBNull(dr["Location"]))
objcmsLocationDO.Location=Convert.ToString(dr["Location"]);
if(!Convert.IsDBNull(dr["Description"]))
objcmsLocationDO.Description=Convert.ToString(dr["Description"]);
if(!Convert.IsDBNull(dr["CreatedDate"]))
objcmsLocationDO.CreatedDate=Convert.ToDateTime(dr["CreatedDate"]);
if(!Convert.IsDBNull(dr["CreatedById"]))
objcmsLocationDO.CreatedById=Convert.ToInt32(dr["CreatedById"]);
if(!Convert.IsDBNull(dr["LastSaveDate"]))
objcmsLocationDO.LastSaveDate=Convert.ToDateTime(dr["LastSaveDate"]);
if(!Convert.IsDBNull(dr["LastModifiedId"]))
objcmsLocationDO.LastModifiedId=Convert.ToInt32(dr["LastModifiedId"]);
if(!Convert.IsDBNull(dr["ParentId"]))
objcmsLocationDO.ParentId=Convert.ToInt32(dr["ParentId"]);
if(!Convert.IsDBNull(dr["OrderId"]))
objcmsLocationDO.OrderId=Convert.ToInt32(dr["OrderId"]);

            }
             return objcmsLocationDO;
        }

        public ArrayList SelectAll1( )
        {
			
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "spcmsLocation_GetAll";
            
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrcmsLocationDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach(DataRow dr in dt.Rows)
{
cmsLocationDO objcmsLocationDO= new cmsLocationDO();
if(!Convert.IsDBNull(dr["LocationId"]))
objcmsLocationDO.LocationId=Convert.ToInt32(dr["LocationId"]);
if(!Convert.IsDBNull(dr["LocationCode"]))
objcmsLocationDO.LocationCode=Convert.ToString(dr["LocationCode"]);
if(!Convert.IsDBNull(dr["Location"]))
objcmsLocationDO.Location=Convert.ToString(dr["Location"]);
if(!Convert.IsDBNull(dr["Description"]))
objcmsLocationDO.Description=Convert.ToString(dr["Description"]);
if(!Convert.IsDBNull(dr["CreatedDate"]))
objcmsLocationDO.CreatedDate=Convert.ToDateTime(dr["CreatedDate"]);
if(!Convert.IsDBNull(dr["CreatedById"]))
objcmsLocationDO.CreatedById=Convert.ToInt32(dr["CreatedById"]);
if(!Convert.IsDBNull(dr["LastSaveDate"]))
objcmsLocationDO.LastSaveDate=Convert.ToDateTime(dr["LastSaveDate"]);
if(!Convert.IsDBNull(dr["LastModifiedId"]))
objcmsLocationDO.LastModifiedId=Convert.ToInt32(dr["LastModifiedId"]);
if(!Convert.IsDBNull(dr["ParentId"]))
objcmsLocationDO.ParentId=Convert.ToInt32(dr["ParentId"]);
if(!Convert.IsDBNull(dr["OrderId"]))
objcmsLocationDO.OrderId=Convert.ToInt32(dr["OrderId"]);
arrcmsLocationDO.Add(objcmsLocationDO);
}
            }
               return arrcmsLocationDO;
        }
        
        public DataTable SelectAll( )
        {
			
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "spcmsLocation_GetAll";
            
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
          
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                
            }
               return dt;
        }

     
		#endregion          
    
    }

}
